fix: set MQTT sessionPresent from cleanSession flag and stored session state (#6889) - #6894
lll-peanut wants to merge 9 commits into
Conversation
|
Good fix — the hardcoded Subscription resume loses QoS. Clean-session state leaks on graceful DISCONNECT (dead-code cleanup). As the PR body notes, Minor (pre-existing, now more reachable): |
Store MQTT session subscriptions with their QoS and resume them through the QoS-aware subscribe repository path. Dispatch DISCONNECT in MqttFactory so clean-session state is removed on graceful disconnect, and unregister disconnected channels from subscriptions. Use computeIfAbsent in SubscribeRepository to avoid concurrent subscribe/resume overwrites.
Thanks for the review. I addressed the three points:
I also added a guard return after rejecting unsupported protocol versions to avoid continuing through authentication/session setup after sending the CONNACK rejection. |
Aias00
left a comment
There was a problem hiding this comment.
Thanks @lll-peanut!
This properly fixes #6889. The session-present handling now follows MQTT-3.2.2-6/7: sessionPresent is only true for a cleanSession=0 connect when the server holds a stored session for the clientId, instead of the old hard-coded sessionPresent(true). The surrounding session semantics look right too:
cleanSession=truediscards any previously stored session;cleanSession=falsecreates a persistent one when absent.- Resuming stored subscriptions (topic + QoS) onto the new channel via
SubscribeRepositorymatches the spec's expectation that a persistent session's subscriptions survive reconnects. - Wiring
DISCONNECTthroughMqttFactorywas the missing dispatch — clean-session state is discarded on graceful disconnect while persistent sessions are kept, and the channel is removed fromSubscribeRepositoryin both cases. Subscribe/Unsubscribenow keep the session's topic→QoS map in sync, including QoS replacement on re-subscribe.- The
computeIfAbsentchange inSubscribeRepository.addalso fixes a real race: the old get-then-put could NPE or lose channels under concurrent subscribes. - Bonus fix: the missing
returnafter refusing an unsupported protocol version previously let CONNECT processing continue — good catch, and the new test pins that behavior down.
Tests cover first connect, reconnect, clean-session discard, subscription resume, QoS retention/replacement, and DISCONNECT dispatch, using Awaitility appropriately for the async repository operations. The single failing check (k8s-examples-http) is unrelated to shenyu-protocol-mqtt.
One note for follow-up (non-blocking): a client that connects with cleanSession=true and then drops the connection without DISCONNECT leaves its clean session in SessionRepository until the next connect replaces it — harmless given connect-time replacement, but worth tracking if session state grows.
LGTM, approving.
|
Heads-up (PMC Aias00): your PR's CI failures are in shared infrastructure checks ( |
fix: #6889
DISCONNECT is now dispatched by MqttFactory, so clean-session sessions are removed on graceful disconnect; the disconnected channel is also removed from SubscribeRepository while persistent session state is kept for resume.
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.